import { defineStore } from 'pinia';
import cookie from '@/utils/cookie';

export const useUserStore = defineStore('user', {
    state: ():UserState => {
        return {
            id: 0,
            username: '',
            name: '',
            token: ''
        }
    },

    actions: {
        updateUserStore() {
            if(cookie.getCookie('USER')){
                const {id, username, name, token} = cookie.getCookie('USER');
                this.id = id;
                this.username = username;
                this.name = name;
                this.token = token;
            }
        }
    }
})

interface UserState {
    id: number;
    username: string;
    name: string;
    token: string
}